﻿using System;
using System.Diagnostics;
using MvcShop.Core.Helper;

namespace MvcShop.Core.Extension
{
    public class Check
    {
        internal Check()
        { }

        public class Argument
        {
            internal Argument()
            { }

            [DebuggerStepThrough]
            public static void IsNotNull(object argument, string argumentName)
            {
                if (argument == null)
                {
                    throw new ArgumentNullException(argumentName);
                }
            }

            [DebuggerStepThrough]
            public static void IsNotEmpty(Guid argument, string argumentName)
            {
                if (argument == Guid.Empty)
                {
                    string message = String.Format("\"{0}\" guid 不能为空.", argumentName);
                    throw new ArgumentException(message);
                }
            }

            [DebuggerStepThrough]
            public static void IsNotEmpty(string argument, string argumentName)
            {
                if (string.IsNullOrEmpty((argument ?? string.Empty).Trim()))
                {
                    string message = String.Format("\"{0}\" 不能为空.", argumentName);
                    throw new ArgumentException(message);
                }
            }

            [DebuggerStepThrough]
            public static void IsNotInPast(DateTime argument, string argumentName)
            {
                if (argument < SystemTime.Now())
                {
                    throw new ArgumentOutOfRangeException(argumentName);
                }
            }

            [DebuggerStepThrough]
            public static void IsNotNegativeOrZero(TimeSpan argument, string argumentName)
            {
                if (argument <= TimeSpan.Zero)
                {
                    throw new ArgumentOutOfRangeException(argumentName);
                }
            }
        }
    }
    
}
